﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SGGWElevator
{
    /// <summary>
    /// Bi-directional dictionary. One key <-> one value.
    /// </summary>
    /// <typeparam name="TFirst">First element of pair.</typeparam>
    /// <typeparam name="TSecond">Second element of pair.</typeparam>
    public class BiDictionary<TFirst, TSecond>
    {
        IDictionary<TFirst, TSecond> firstToSecond = new Dictionary<TFirst, TSecond>();
        IDictionary<TSecond, TFirst> secondToFirst = new Dictionary<TSecond, TFirst>();

        public void Add(TFirst first, TSecond second)
        {
            if (firstToSecond.ContainsKey(first) ||
                secondToFirst.ContainsKey(second))
            {
                throw new ArgumentException("Duplicate first or second");
            }
            firstToSecond.Add(first, second);
            secondToFirst.Add(second, first);
        }
       
        public TSecond GetByFirst(TFirst first)
        {
            return firstToSecond[first];
        }

        public TFirst GetBySecond(TSecond second)
        {
            return secondToFirst[second];
        }
    }
}
